<?php
require_once 'common/session.inc.php';
include_once 'common/config.inc.php';
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>动态列表</title>
    <link href="Images/css1/css.css" rel="stylesheet" type="text/css">
    <style>
        td, th {
            text-align: center
        }
        a{
            cursor: pointer
        }
    </style>
    <script type='text/javascript' src='public/jquery-1.10.1.min.js'></script>
    <script type='text/javascript' src='public/layer/layer.js'></script>
    <script>
     $(function(){

         //批量删除
        $('#delete').click(function(){

            var arr = new Array();
            $('input[type=checkbox]:checked').each(function(){

                arr.push($(this).val());

            });

            console.log(arr.join(','));

            if(arr.length==0){

                layer.msg('请至少选中一个!',function(){});

            }else{

                layer.confirm('确定要删除吗?',{btn:['确定','取消']},function(){
                    //关闭所有layer效果
                    layer.closeAll();
                    $.ajax({
                        type:"POST",
                        url:"news_deal.php?act=del",
                        data:'id='+arr.join(','),
                        dataType:'json',
                        success:function(res){

                            if(res['status']==1){

                                layer.msg(res.msg, {icon: 6});
                                setTimeout("location.reload()",1500);

                            }else{

                                layer.msg(res.msg, {icon: 5});

                            }

                        }


                    });

                },function(){});

            }




        });



     });
    </script>
</head>
<body>
<form method='post' action=''>
    <table class="table" cellspacing="1" cellpadding="2" width="99%"
           align="center" border="0">
        <tbody>
        <tr>
            <th class="bg_tr" align="left" height="25">序号</th>
            <th class="bg_tr" align="left" height="25">所属分类</th>
            <th class="bg_tr" align="left" height="25">动态名称</th>
            <th class="bg_tr" align="left" height="25">简要描述</th>
            <th class="bg_tr" align="left" height="25">修改</th>
            <th class="bg_tr" align="left" height="25">
                <input type='button' id='delete' name='deleteSubmit' onclick="" value='删除' />
            </th>
        </tr>
    <?php
        include_once 'common/mysql.inc.php';
        //$sql = "select * from bbs_news order by id DESC";
        //获取总数据量$sum
        $data = mysql_fetch_assoc(mysql_query("select count(*) as num from bbs_news"));
        $sum = $data['num'];

        //定义每页显示数量$pagesize
        $pagesize = 5;

        //最大页数
        $max = ceil($sum/$pagesize);

        //定义当前页码


        $page = isset($_GET['page'])?$_GET['page']:1;

        //获取上一页,下一页
        $prev = $page-1;
        $next = $page+1;

        //越界处理
        if($prev<1){

            $prev = 1;

        }

        if($next>$max){

            $next = $max;

        }

        //echo $page;

        //偏移量(从哪个数据开始查询的最小为0)
        $start = $pagesize*($page-1);

        $sql = "select * from bbs_news order by id asc limit $start,$pagesize";

        $res = mysql_query($sql);

        while($row = mysql_fetch_assoc($res)){

    ?>
        <tr>
            <td class="td_bg" width="5%" height="23" align="center"><?php echo $row['id']; ?></td>
            <td class="td_bg" width="10%">
            <!--  所属分类   -->
                <?php
                foreach($newstype as $v){
                    if($row['cid'] ==$v[0]){
                        echo $v[1];
                    }
                }
                ?>
            </td>
            <td class="td_bg" width="10%"><?php echo $row['title']; ?></td>
            <td class="td_bg"><?php echo $row['description']; ?></td>
            <td class="td_bg"><a href="news_edit.php?id=<?php echo $row['id'] ;?>">修改</a></td>
            <td class="td_bg"><input type='checkbox' value="<?php echo $row['id'] ;?>" name='id[]' /></td>
        </tr>
                <?php

                    }

                ?>
        <tr>
            <td colspan="6">
                <a href="news_list.php?page=1">首页</a>
                <a href="news_list.php?page=<?php echo $prev;?>">上一页</a>
                <a href="news_list.php?page=<?php echo $next;?>">下一页</a>
                <a href="news_list.php?page=<?php echo $max; ?>">末页</a>
            </td>
        </tr>
        </tbody>
    </table>
</form>
</body>
</html>